#include <REGX52.H>
#include "delay.h"
#include "timer0.h"

sbit DA = P2^1;

unsigned char counter, compare;
unsigned char i;

void main()
{
	timer0_init();	
	while(1)
	{
		for(i = 0; i < 100; i++)
		{
			compare = i;
			delay(10);
		}
		for(i = 100; i > 0; i--)
		{
			compare = i;
			delay(10);
		}
	}
}


void Time0_Rountine() interrupt 1
{
	TL0 = 0xA4;		//设置定时初值
	TH0 = 0xFF;		//设置定时初值
	counter++;
	counter %= 100;	//计数值变化范围限制在0~99
	if(counter < compare)	//计数值小于比较值
	{
		DA = 1;		//输出1
	}
	else				//计数值大于比较值
	{
		DA = 0;		//输出0
	}
}
